package com.run2code.controller;

import com.run2code.service.ExportService;
import com.run2code.service.ImportService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 薪资控制器，模拟导入导出的入口
 *
 * @author 第七人格
 * @date 2023/09/28
 */

@RestController
public class SalariesController {

    /**
     * 导入服务
     */
    @Resource
    private ImportService importService;

    /**
     * 导出服务
     */
    @Resource
    private ExportService exportService;

    /**
     * 导入excel
     *
     * @param file
     * @throws IOException
     */
    @PostMapping("import")
    public void importExcel(MultipartFile file) throws IOException {
        importService.importExcel(file);
    }

    /**
     * 导出excel
     *
     * @param response
     * @throws IOException
     * @throws InterruptedException
     */
    @GetMapping("export")
    public void exportExcel(HttpServletResponse response) throws IOException, InterruptedException {
        exportService.exportExcel(response);
    }
}
